package offer.algorithm;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/28 13:52
 */
public class Multiply52 {

    public static Integer[] getMultiArray(Integer[] array) {
        if (array == null || array.length <= 1)
            return array;
        int length = array.length;
        Integer[] temp = new Integer[ length ];
        temp[ 0 ] = array[ 0 ];
        for (int i = 1; i < length; ++i) {
            temp[ i ] = temp[ i - 1 ] * array[ i ];
        }
        temp[ length - 1 ] = temp[ length - 2 ];
        for (int i = length - 2; i > 0; --i) {
            array[ i ] = array[ i ] * array[ i + 1 ];
            temp[ i ] = temp[ i - 1 ] * array[ i + 1 ];
        }
        temp[ 0 ] = array[ 1 ];
        return temp;
    }
}
